package com.example.demo.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.entity.Authority;
import com.example.demo.mapper.AuthorityMapper;
import com.example.demo.service.AuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuthorityServiceImpl implements AuthorityService {

    @Autowired
    AuthorityMapper authorityMapper;

    @Override
    public List<Authority> getAuthorityListByUsername(String username) {
        return authorityMapper.getAuthorityListByUsername(username);
    }

    @Override
    public List<Authority> selectAllAuthorityListOrOne(Authority authority) {
        List<Authority> authorityList;
        if (authority.getAuthorityName() != null && (!authority.getAuthorityName().equals(""))) {
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.eq("authority_name", authority.getAuthorityName());
            authorityList = authorityMapper.selectList(wrapper);
        } else {
            authorityList = authorityMapper.selectList(null);
        }
        return authorityList;
    }

    @Override
    public int insertAuthority(Authority authority) {
        return authorityMapper.insert(authority);
    }

    @Override
    public Integer getAllAuthorityListCount() {
        return authorityMapper.getAllAuthorityListCount();
    }
}
